import { Orderss } from './orders';
let _Orderss = Orderss;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import OrdersMock from './mallm/orders/ordersMock';
 * OrdersMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mallm/orders/orders/listKey').reply(config => {
      let params = config.params;
      let mockOrderss = _Orderss.filter(orders => {
      	if(params.id||params.id==''){ if( orders.id.indexOf(params.id)>=0) return true;}
      	if(params.orderSn||params.orderSn==''){ if( orders.orderSn.indexOf(params.orderSn)>=0) return true;}
      	if(params.userid||params.userid==''){ if( orders.userid.indexOf(params.userid)>=0) return true;}
      	if(params.orderStatus||params.orderStatus==''){ if( orders.orderStatus.indexOf(params.orderStatus)>=0) return true;}
      	if(params.payStatus||params.payStatus==''){ if( orders.payStatus.indexOf(params.payStatus)>=0) return true;}
      	if(params.payId||params.payId==''){ if( orders.payId.indexOf(params.payId)>=0) return true;}
      	if(params.payName||params.payName==''){ if( orders.payName.indexOf(params.payName)>=0) return true;}
      	if(params.shippingFee||params.shippingFee==''){ if( orders.shippingFee.indexOf(params.shippingFee)>=0) return true;}
      	if(params.actualPrice||params.actualPrice==''){ if( orders.actualPrice.indexOf(params.actualPrice)>=0) return true;}
      	if(params.orderPrice||params.orderPrice==''){ if( orders.orderPrice.indexOf(params.orderPrice)>=0) return true;}
      	if(params.goodsPrice||params.goodsPrice==''){ if( orders.goodsPrice.indexOf(params.goodsPrice)>=0) return true;}
      	if(params.addTime||params.addTime==''){ if( orders.addTime.indexOf(params.addTime)>=0) return true;}
      	if(params.confirmTime||params.confirmTime==''){ if( orders.confirmTime.indexOf(params.confirmTime)>=0) return true;}
      	if(params.payTime||params.payTime==''){ if( orders.payTime.indexOf(params.payTime)>=0) return true;}
      	if(params.freightPrice||params.freightPrice==''){ if( orders.freightPrice.indexOf(params.freightPrice)>=0) return true;}
      	if(params.parentId||params.parentId==''){ if( orders.parentId.indexOf(params.parentId)>=0) return true;}
      	if(params.reduceMoney||params.reduceMoney==''){ if( orders.reduceMoney.indexOf(params.reduceMoney)>=0) return true;}
      	if(params.increaseBonus||params.increaseBonus==''){ if( orders.increaseBonus.indexOf(params.increaseBonus)>=0) return true;}
      	if(params.reduceBonus||params.reduceBonus==''){ if( orders.reduceBonus.indexOf(params.reduceBonus)>=0) return true;}
      	if(params.bonusMoney||params.bonusMoney==''){ if( orders.bonusMoney.indexOf(params.bonusMoney)>=0) return true;}
      	if(params.shippingStatus||params.shippingStatus==''){ if( orders.shippingStatus.indexOf(params.shippingStatus)>=0) return true;}
      	if(params.deptid||params.deptid==''){ if( orders.deptid.indexOf(params.deptid)>=0) return true;}
      	if(params.remark||params.remark==''){ if( orders.remark.indexOf(params.remark)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockOrderss
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mallm/orders/orders/list').reply(config => {
      let params = config.params;
      let mockOrderss = _Orderss.filter(orders => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(orders.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderSn||params.orderSn==''){if(orders.orderSn.indexOf(params.orderSn)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userid||params.userid==''){if(orders.userid.indexOf(params.userid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderStatus||params.orderStatus==''){if(orders.orderStatus.indexOf(params.orderStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.payStatus||params.payStatus==''){if(orders.payStatus.indexOf(params.payStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.payId||params.payId==''){if(orders.payId.indexOf(params.payId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.payName||params.payName==''){if(orders.payName.indexOf(params.payName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shippingFee||params.shippingFee==''){if(orders.shippingFee.indexOf(params.shippingFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.actualPrice||params.actualPrice==''){if(orders.actualPrice.indexOf(params.actualPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderPrice||params.orderPrice==''){if(orders.orderPrice.indexOf(params.orderPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsPrice||params.goodsPrice==''){if(orders.goodsPrice.indexOf(params.goodsPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.addTime||params.addTime==''){if(orders.addTime.indexOf(params.addTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.confirmTime||params.confirmTime==''){if(orders.confirmTime.indexOf(params.confirmTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.payTime||params.payTime==''){if(orders.payTime.indexOf(params.payTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.freightPrice||params.freightPrice==''){if(orders.freightPrice.indexOf(params.freightPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.parentId||params.parentId==''){if(orders.parentId.indexOf(params.parentId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.reduceMoney||params.reduceMoney==''){if(orders.reduceMoney.indexOf(params.reduceMoney)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.increaseBonus||params.increaseBonus==''){if(orders.increaseBonus.indexOf(params.increaseBonus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.reduceBonus||params.reduceBonus==''){if(orders.reduceBonus.indexOf(params.reduceBonus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bonusMoney||params.bonusMoney==''){if(orders.bonusMoney.indexOf(params.bonusMoney)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shippingStatus||params.shippingStatus==''){if(orders.shippingStatus.indexOf(params.shippingStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.deptid||params.deptid==''){if(orders.deptid.indexOf(params.deptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remark||params.remark==''){if(orders.remark.indexOf(params.remark)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockOrderss
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockOrderss.length;
      mockOrderss = mockOrderss.filter((orders, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockOrderss,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mallm/orders/orders/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _Orderss = _Orderss.filter(orders => orders.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mallm/orders/orders/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _Orderss = _Orderss.filter(orders => !params.includes(orders.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mallm/orders/orders/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,orderSn,userid,orderStatus,payStatus,payId,payName,shippingFee,actualPrice,orderPrice,goodsPrice,addTime,confirmTime,payTime,freightPrice,parentId,reduceMoney,increaseBonus,reduceBonus,bonusMoney,shippingStatus,deptid,remark } = params;
      _Orderss.some(orders => {
        if (orders.id === id) {
			orders.id = id;
			orders.orderSn = orderSn;
			orders.userid = userid;
			orders.orderStatus = orderStatus;
			orders.payStatus = payStatus;
			orders.payId = payId;
			orders.payName = payName;
			orders.shippingFee = shippingFee;
			orders.actualPrice = actualPrice;
			orders.orderPrice = orderPrice;
			orders.goodsPrice = goodsPrice;
			orders.addTime = addTime;
			orders.confirmTime = confirmTime;
			orders.payTime = payTime;
			orders.freightPrice = freightPrice;
			orders.parentId = parentId;
			orders.reduceMoney = reduceMoney;
			orders.increaseBonus = increaseBonus;
			orders.reduceBonus = reduceBonus;
			orders.bonusMoney = bonusMoney;
			orders.shippingStatus = shippingStatus;
			orders.deptid = deptid;
			orders.remark = remark
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mallm/orders/orders/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,orderSn,userid,orderStatus,payStatus,payId,payName,shippingFee,actualPrice,orderPrice,goodsPrice,addTime,confirmTime,payTime,freightPrice,parentId,reduceMoney,increaseBonus,reduceBonus,bonusMoney,shippingStatus,deptid,remark } = params;
      _Orderss.push({
		id:id,
		orderSn:orderSn,
		userid:userid,
		orderStatus:orderStatus,
		payStatus:payStatus,
		payId:payId,
		payName:payName,
		shippingFee:shippingFee,
		actualPrice:actualPrice,
		orderPrice:orderPrice,
		goodsPrice:goodsPrice,
		addTime:addTime,
		confirmTime:confirmTime,
		payTime:payTime,
		freightPrice:freightPrice,
		parentId:parentId,
		reduceMoney:reduceMoney,
		increaseBonus:increaseBonus,
		reduceBonus:reduceBonus,
		bonusMoney:bonusMoney,
		shippingStatus:shippingStatus,
		deptid:deptid,
		remark:remark
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};